package com.fenghongzhang.day009test;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MySqlHelp extends SQLiteOpenHelper {
    public MySqlHelp(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table apple(id integer primary key autoincrement , name varchar(20),price integer)");
        db.beginTransaction();

        for (int i = 0; i < 1; i++) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("name","红富士");
            contentValues.put("price",20);
            db.insert("apple",null,contentValues);
        }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
